Replace print() error output with structured logging (#68)#77
Replace print() error output with structured logging (#68)#77bradjin8 wants to merge 12 commits into
Conversation
Linux CI pip-compile now resolves click==8.4.1 within the flask bound; the lock still pinned 8.4.0, which failed the lockfile freshness job.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughReplace print/silent-except error paths with module-level logging, add logging.basicConfig in app factory, convert prints to _logger.warning/_logger.error (use exc_info where used), and add tests that assert emitted warnings for parse/schema-drift failures. ChangesStructured Logging Across API and Service Layers
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@services/workspace_listing.py`:
- Line 137: The top-level composer load error log currently drops stack context
by calling _logger.error("Failed to load composer rows from global storage: %s",
e); update that call to include the exception traceback by passing exc_info=True
(i.e., _logger.error(..., exc_info=True)) so the stack trace is preserved for
operational debugging while keeping the existing message and exception
interpolation.
In `@services/workspace_tabs.py`:
- Around line 126-131: The warning currently logs the raw cursorDiskKV payload
(row["value"]) which can leak sensitive conversation data and be very large;
update the _logger.warning call(s) that reference row["value"] (the one shown
and the similar block around lines 210-215) to avoid including the raw payload
and instead log stable identifiers and payload size — keep row["key"] (or any
available stable id like bubble id) and add payload length (e.g.,
len(row.get("value", b"")) or length of the string) and/or a checksum/short hash
if you need a stable fingerprint; update the _logger.warning invocations in
workspace_tabs.py that currently format row["value"] accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: aced6938-416d-42b6-b9e3-5c4e0857d0f0
📒 Files selected for processing (17)
api/composers.pyapi/config_api.pyapi/export_api.pyapi/logs.pyapi/pdf.pyapi/search.pyapi/workspaces.pyapp.pyrequirements-lock.txtservices/cli_tabs.pyservices/workspace_listing.pyservices/workspace_resolver.pyservices/workspace_tabs.pytests/test_invalid_workspace_aliases.pytests/test_models_wired_at_read_sites.pytests/test_parse_failure_logging.pytests/test_workspace_tabs_null_bubble.py
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@services/workspace_tabs.py`:
- Around line 138-145: The JSON decode guard around json.loads in
services/workspace_tabs.py currently only catches json.JSONDecodeError; change
those except clauses (the one around the block that calls _kv_payload_log_meta
and logs via _logger.warning with row["key"] and e) to catch
(json.JSONDecodeError, TypeError, ValueError) so non-text SQLite values or other
decode issues are treated non-fatal; apply the same change to the other
symmetric decode block that logs payload_len/payload_fp (the second handler that
currently only catches JSONDecodeError) so both malformed KV row paths behave
consistently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 65d3d309-c7f4-4f28-8a15-8bc988cd7bf5
📒 Files selected for processing (2)
services/workspace_listing.pyservices/workspace_tabs.py
7238424 to
e97f28e
Compare
Should fixutils/cli_chat_reader.py:103 — replace print(f"Schema drift in CLI session meta at {db_path}: {e}") with _logger.warning("Schema drift in CLI session meta at %s: %s", db_path, e) and add _logger = logging.getLogger(name) to the module. (only unstructured error print remaining in a module on the schema-drift path; same pattern as every other call replaced by this PR) Nice to haveservices/workspace_tabs.py:41 — _try_loads_kv_value still has two callers in the unchanged codeBlockDiff loading block (lines 165 and 183) and is not dead code, but those callers silently swallow decode failures the same way the old bubble/composer paths did. Migrating them to explicit json.loads + _logger.warning(...) would make the coverage consistent with the rest of the file. scripts/export.py:350, :381 — print(f"Warning: ...", file=sys.stderr) patterns remain. Stderr is acceptable for a CLI tool, but routing through logging would make the output capturable by the same log configuration and consistent with the new project standard. |
Summary
create_app()(logging.basicConfigat INFO, format includes module and function name for gunicorn/WSGI capture).print()calls inservices/andapi/with module loggers (logging.getLogger(__name__)) usingwarningfor schema drift anderrorwithexc_info=Truefor unexpected failures.traceback.print_exc()from export/PDF handlers in favor of structured traceback viaexc_info=True.test_bubble_schema_drift_is_logged_not_swallowed_silentlyto assert on log output (assertLogs) instead of stdout.Closes #68. Complements #66 (except-pass → logging): services that already logged parse failures are unchanged; this PR finishes Test 10 coverage for paths that still used
print().Files touched:
app.py,services/cli_tabs.py,api/composers.py,api/search.py,api/export_api.py,api/pdf.py,api/config_api.py,tests/test_models_wired_at_read_sites.pyOut of scope:
scripts/export.pyCLI stderr warnings (not underservices//api/per issue).Test plan
python -m pytest -q— 306 passed, 4 skippedprint(calls remain inservices/orapi/DEPLOYMENT.mdSummary by CodeRabbit
Bug Fixes
Chores
Tests